package com.topView2;

import java.util.HashMap;
import java.util.Map;
import java.util.Stack;

/**
 * @Author: huangzhigao
 * @Date: 2023/2/12 13:12
 */
public class leecode20 {
    public boolean isValid(String s) {
        Stack<Character> stack = new Stack<>();
        char[] chars = s.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            if (chars[i] == '(' || chars[i] == '{' || chars[i] == '[') {
                stack.push(chars[i]);
            } else {
                if (stack.isEmpty()) {
                    return false;
                }
                Character pop = stack.pop();
                Character v = isV(chars[i]);
                if (v != pop) {
                    return false;
                }
            }
        }
        return stack.isEmpty();
    }

    public Character isV(Character s) {
        switch (s) {
            case ')':
                return '(';
            case ']':
                return '[';
            case '}':
                return '{';
        }
        return null;
    }

}
